package com.ihg.hiex.admin.processor.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.demo2do.core.entity.result.HttpResult;
import com.demo2do.core.http.annotation.Rao;
import com.demo2do.core.utils.JsonUtils;
import com.ihg.hiex.admin.processor.SendEmailProcessor;
import com.ihg.hiex.admin.rao.SendEmailRao;
import com.ihg.hiex.entity.session.Session;

/**
 * 
 * @author houtao
 * 
 */
@Component("sendEmailProcessor")
public class SendEmailProcessorImpl implements SendEmailProcessor {

    private static final Logger logger = LoggerFactory.getLogger(SendEmailProcessorImpl.class);

    @Value("#{send['send.sendUrl']}")
    private String sendUrl;
    
    @Rao
    private SendEmailRao sendEmailRao;

    /* (non-Javadoc)
     * @see com.ihg.hiex.admin.processor.SendEmailProcessor#send(java.lang.String, com.ihg.hiex.entity.session.Session)
     */
    public void send(String code, Session session) {
        
        Map<String, Object> parameter = new HashMap<String, Object>();
        parameter.put("sessionId", session.getId());
        parameter.put("code", code);
        
        logger.trace("#send() - send email, url=[{}] parameters=[{}]", sendUrl, JsonUtils.toJson(parameter));
        
        HttpResult httpResult = sendEmailRao.send(sendUrl, parameter);
        if(!httpResult.isValid()) {
            logger.error("#send - send email occurs error, the result is [{}]", JsonUtils.toJson(httpResult));
        }
        
    }
    
}
